<template>
	<view class="classlist">
		<view class="content">
			<navigator :url="'/pages/preview/preview?id=' + item.id" class="item" v-for="item in WallList">
				<image :src="item.smallPicurl" mode="aspectFill"></image>
			</navigator>
		</view>
	</view>
</template>

<script setup>
import {onLoad , onUnload , onShareAppMessage , onShareTimeline , onReachBottom} from "@dcloudio/uni-app"
import { ref } from "vue";
import { apiWallList } from "../../api/api";
//Params携带请求参数
const queryParams = {
	id:1,
	pageNum:1,
	pageSize:12
}

//onLoad生命周期钩子获取页面参数
onLoad((e)=>{
    let {id = null,
    name = null} = e;
    if(id){
    	queryParams.id = id;
    }
	//改变头部信息
	uni.setNavigationBarTitle({
		title:name
	})
	//获取分类列表
	getWallList()
})

//获取分类列表
const WallList = ref([])
const getWallList =async()=>{
	const res =  await apiWallList(queryParams)
	//数组拼接实现下拉刷新
	WallList.value = [...WallList.value,...res.data.data]
	//判断数据是否无数据
	if(queryParams.pageSize > res.data.length) noData.value= true;
	//存入本地缓存
	uni.setStorageSync("storgClassList",WallList.value)
}

//触底刷新更多
const noData = ref(false)
onReachBottom(()=>{
	if(noData.value) return;
	queryParams.pageNum++
	getWallList();
})
//分享给好友
onShareAppMessage((e)=>{
	return{
		title:"cheems壁纸"+pageName,
		path:"/pages/classlist/classlist?id="+queryParams.classid+"&name=" + pageName
	}
})

//分享到朋友圈
onShareTimeline(()=>{
	return{
		title:"cheems壁纸"+pageName,
		query:"id="+queryParams.classid+"&name=" + pageName
	}
})

//推出删除缓存
onUnload(()=>{
	uni.removeStorageSync("storgClassList")
})
</script>

<style lang="scss" scoped>
.classlist{
	.content{
		display: grid;
		grid-template-columns: repeat(3,1fr);
		gap:5rpx;
		padding:5rpx;
		.item{
			height: 440rpx;
			image{
				width: 100%;
				height: 100%;
				display: block;
			}
		}
	}
}
</style>
